# import pygame, math and random
import pygame as pg
import math, random

# init program
pg.init()
screen = pg.display.set_mode((1000, 800))
pg.display.set_caption("Code5-2-4_pygame_WaterWave", "2.0")

# pos
pos = [0, 600]
# waveX
waveX = 0
# waveY
waveY = 0
# y
y = 1

# check loop and fps
fps = pg.time.Clock()
while True:
    # fps tick
    fps.tick(60)
    # check quit
    event = pg.event.poll()
    if event.type == pg.QUIT:
        pg.quit()
        exit()
    # fill screen
    screen.fill((255, 255, 255))
    waveX += random.uniform(0.05, 0.1)  # random.uniform is used for decimal representation
    # switch thinking again!
    waveY += y
    if waveY == -5:
        y = 1  # speed change
    if waveY == 200:
        y = -1  # speed change
    # draw
    for i in range(250):
        # posX change
        pos[0] = 4 * i
        # posY change
        for j in range(50):
            # use math.sin
            pos[1] = 10 * j + 600 + waveY * math.sin(i / 40 + waveX)
            # draw circles
            pg.draw.circle(screen, (0, 55, 120), pos, 10, 0)
    # display program
    pg.display.update()